package 力扣.位运算.移位运算;

public class 位1的个数191 {
    public int hammingWeight(int n) {
        int count = 0;
        while (n != 0){
            n &= (n-1);//可以将最低位的那个一变为0
            count++;
        }
        return count;
    }
    public int hammingWeight2(int n) {
        if (n == 0){
            return 0;
        }
        int i = n & 1;
        return i + hammingWeight(n >> 1);
    }
}
